﻿using System;
using System.Collections.Generic;
using System.Text;
using Mind.Data;


namespace Mind.SampleProject.Data
{

    public class ProductTypeSchema : Schema<ProductTypeSchema>
    {
        private const string _TableName = "ProductType";
        public const string ProductTypeIdColumn = "ProductTypeId";
        public const string NameColumn = "Name";

        protected override void GenerateColumns()
        {
            AddColumnInfo(ColumnInfo.CreatePrimaryKeyColumn(ProductTypeIdColumn, typeof(int)));
            AddColumnInfo(ColumnInfo.CreateNormalColumn(NameColumn, typeof(string), false, 0));
        }

        protected override void GenerateLockups()
        {
            
        }

        protected override string GetTableName()
        {
            return _TableName;
        }
    }


    public partial class ProductType : Wrapper<ProductType, ProductTypeSchema>
    {


        public int ProductTypeId
        {
            get
            {
                return GetColumnValue<int>(ProductTypeSchema.ProductTypeIdColumn).GetValueOrDefault();
            }

            set
            {
                SetColumnValue(ProductTypeSchema.ProductTypeIdColumn, value);
            }
        }

        public string Name
        {
            get
            {
                return GetColumnString(ProductTypeSchema.NameColumn);
            }

            set
            {
                SetColumnValue(ProductTypeSchema.NameColumn, value);
            }
        }

        public DataReaderIterator<Product> GetProducts()
        {
            return Product.FindByColumn(ProductSchema.ProductTypeIdColumn, this.ProductTypeId);
        }


    }


    
    
}
